//
//  Header.swift
//  Automobile
//
//  Created by erkebulan elzhan on 7/25/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.
//

import UIKit
import SnapKit


final class HomeHeaderView: UIView {
    lazy private var titleLbl: UILabel = {
        let lbl = UILabel()
        lbl.font = UIFont.systemFont(ofSize: 24, weight: .bold)
        lbl.textColor = .black
        lbl.sizeToFit()
        return lbl
    }()
    lazy private var balanceWrapper: UIView = {
        let view = UIView ()
        view.backgroundColor = .blueColor
        view.clipsToBounds = true
        view.layer.cornerRadius = 15
        return view
    }()
    lazy private var balanceLbl: UILabel = {
        let lbl = UILabel ()
        lbl.font = UIFont.systemFont(ofSize: 17, weight: .medium)
        lbl.textColor = .white
        lbl.sizeToFit()
        return lbl
    }()
    
    
    init (user: User) {
        super.init(frame: .zero)
        balanceLbl.text = "Счет: \(user.balance) T"
        titleLbl.text = "Привет, \(user.name)"
        self.addUIConstraints()
    }
    

    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func addUIConstraints () {
        self.addSubview(balanceWrapper)
        self.addSubview(titleLbl)
        balanceWrapper.addSubview(balanceLbl)
        
        
        balanceLbl.snp.makeConstraints { (make) in
            make.centerX.centerY.equalToSuperview()
            make.leading.trailing.equalToSuperview().inset(30)
        }
        
        balanceWrapper.snp.makeConstraints { (make) in
            make.bottom.trailing.equalToSuperview().inset(16)
            make.height.equalTo(44)
        }
        
        titleLbl.snp.makeConstraints { (make) in
            make.centerY.equalTo(balanceWrapper)
            make.leading.equalToSuperview().offset(16)
            
        }
    }
}
